﻿#pragma once

#include <string>
#include <sstream>
#include <iostream>
#include <sstream>

#include "platform_config.h"
#include "unicode.hpp"
#include "str_converter.h"


#if defined(_MSC_VER) && _MSC_VER <= 1600
#include <cstdarg>
namespace std
{
	inline int snprintf(char* buffer, size_t count, const char* format, ...)
	{
		va_list va;
		va_start(va, format);
		int n = ::_vsnprintf(buffer, count, format, va);
		buffer[count-1] = '\0';
		va_end(va);
		return n;
	}

	inline int snwprintf(wchar_t* buffer, size_t count, const wchar_t* format, ...)
	{
		va_list va;
		va_start(va, format);
		int n = ::_vsnwprintf(buffer, count, format, va);
		buffer[count-1] = L'\0';
		va_end(va);
		return n;
	}
};
#endif // namespace std;


namespace helpers {
	namespace text {

#ifdef CHARSET_UNICODE
		typedef wchar_t tchar;
		typedef std::wstring tstring;

		typedef std::wostream tostream;
		typedef std::wistream tistream;

		typedef std::wofstream tofstream;
		typedef std::wostringstream tostringstream;

		static tostream &tcout = std::wcout;
		static tostream &tcerr = std::wcerr;

#else
		typedef char tchar;
		typedef std::string tstring;

		typedef std::ostream tostream;
		typedef std::istream tistream;

		typedef std::ofstream tofstream;

		typedef std::ostringstream tostringstream;

		static tostream &tcout = std::cout;
		static tostream &tcerr = std::cerr;

#endif // UNICODE

	} // namespace text
} // namespace helpers




#if defined CHARSET_UNICODE
#	define T_TEXT(x)	L ## x
#	define sntprintf	snwprintf
#	define stscanf		swscanf
#	define tcsnccpy		wcsncpy
#	define tcscpy		wcscpy
#	define tcsstr		wcsstr
#	define tcslen		wcslen
#	define tcstol		wcstol
#	define tcscmp		wcscmp
#else
#	define T_TEXT(x)	x
#	define sntprintf	snprintf
#	define stscanf		sscanf
#	define tcsnccpy		strncpy
#	define tcscpy		strcpy
#	define tcsstr		strstr
#	define tcslen		strlen
#	define tcstol		strtol
#	define tcscmp		strcmp
#	endif


#if defined(CHARSET_UNICODE)
#
#	define C_STR_TO_TSTRING(X)		::helpers::text::ToWString(X)
#	define STRING_TO_TSTRING(X)		::helpers::text::ToWString(X)
#	define TSTRING_TO_STRING(X)		::helpers::text::ToString(X)
#
#else
#
#	define C_STR_TO_TSTRING(X)	std::string(X)
#	define STRING_TO_TSTRING(X) X
#	define TSTRING_TO_STRING(X) X
#
#endif
